package main

import (
	"AttackTracer/TracingEngine/RPC"
	"AttackTracer/TracingEngine/config"
	"AttackTracer/TracingEngine/resourseMonitor"
	"fmt"
	"os"
)

var (
	Conf config.Config
)

func init() {
	// get config file path from command line
	var configPath string
	if len(os.Args) != 2 {
		fmt.Println("no config file provided")
		configPath = "/etc/AttackTracer/tracing_engine.yaml"
	} else {
		configPath = os.Args[1]
	}
	fmt.Println("reading config from " + configPath)

	// parse config
	Conf, err := Conf.Parse(configPath)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	if err = Conf.Validate(); err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	//log.Print(Conf)
}

func main() {
	fmt.Println("TracingEngine starting")
	go resourseMonitor.MonitorResourse()
	RPC.Serve(Conf.RpcConf)
}
